import torch

y_true = torch.tensor([2,2,2],dtype = torch.float)
y_pred = torch.tensor([1.2,1.7,1.9],requires_grad=True)



# 创建MAE损失函数
mae_loss_func = torch.nn.L1Loss()

# 计算MAE损失
loss_func = mae_loss_func(y_pred, y_true)

print(loss_func)


# 创建mse损失函数
mse_loss = torch.nn.MSELoss()
loss = mse_loss(y_pred, y_true)
print(loss)


# 创建SmoothL1损失函数
l_loss = torch.nn.SmoothL1Loss()
l_loss1 = l_loss(y_pred, y_true)
print(l_loss1)
